﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KBasedNumber.Question;

namespace KBasedNumber.Answer
{
    class Albin:IKBasedNumber
    {
        public int KBasedNumber(int n, int k)
        {
            int count = 0;
            count += (int)Math.Pow(k - 1, n);
            int m = n/2;
            int s = 1;
            if (n % 2 == 0)
            {
                s--;
            }
            while (m-- > 0)
            {
                count += (n - (2 * s + 1)) * (int)Math.Pow(k - 1, n - s - 1);
                s++;
            }
            return count;
        }
    }
}
